/*
 * @Author: your name
 * @Date: 2021-12-20 19:10:44
 * @LastEditTime: 2021-12-21 18:59:55
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \day10 react\my-app\src\views\classify\classify.js
 */
import React, { Component } from 'react';
// import {getclassify} from "../../api/api"
import Item from "../../component/Item"
import Header from "../../component/Header"
import "../../../node_modules/react-vant/lib/index.css"
import {connect} from "react-redux"
import {getclassify,changeStart} from "../../store/action"
 
class Classify extends Component {

    state={
        list:[]
    }

    async componentDidMount(){
        // console.log(this.props);
        let {type}=this.props.location.query
        // let res=await getclassify({type})
        // this.setState({
        //     list:res.data
        // })
        this.props.getClassify(type)
    }

    changeStarts(obj){
        console.log(obj);
        this.props.edit(obj)
    }

    change_item(obj,index){
        console.log(obj,index);
        this.props.edit({...obj,flag:index})
    }
 
    render() { 
        let {list}=this.props
        return (
            <div>
                <Header {...this.props} name="分类查询"/>
                {
                    list&&list.length?list.map((item,index) => {
                        return <Item key={index} item={item} changeStarts={this.changeStarts.bind(this)} change_item={this.change_item.bind(this)}/>
                    }):<div>暂无数据</div>
                }
            </div>
        );
    }
}
 
export default connect((state)=>{
    return {
        list:state.classify
    }
},(dispatch)=>{
    return {
        getClassify(type){
            dispatch(getclassify(type))
        },
        edit(obj){
            dispatch(changeStart(obj))
        }
    }
})(Classify);